<template>
	<view class="page" style="padding-bottom: 50rpx;">
		<view class="topVue">
			<view class="safeVue" :style="{ height: statusBarHeight + 'rpx' }"></view>
			<view class="flex align-center padding-row30" :style="{ height: barHeight + 'rpx', top: statusBarHeight + 'rpx' }" @click="$tools.back()">
				<image src="../../static/back.png" style="width: 48rpx; height: 48rpx;"></image>
				<text style="line-height: 1; color: #454545; font-weight: 600; font-size: 32rpx; padding-left: 20rpx;">店铺订单</text>
			</view>
		</view>
		<view :style="{ height: statusBarHeight + barHeight + 'rpx' }"></view>
		<view class="tabVue margin10">
			<u-tabs 
				:list="tabs" 
				:is-scroll="false" 
				:current="current" 
				@change="tabChange"
				name="classifyName"
				active-color="#D37430"
			></u-tabs>
		</view>
		<u-empty text="列表为空" mode="list" v-if="list.length===0" margin-top="200"></u-empty>
		<view class="item margin20 padding30" v-for="(item, index) in list" :key="index">
			<view class="flex-between align-center">
				<text style="line-height: 1; color: #333; font-weight: 600;">{{item.shopName}}</text>
				<text style="line-height: 1; color: #454545; font-weight: 600;">{{item.createTime}}</text>
			</view>
			<view class="flex margin30" v-for="(o, i) in item.orderItems" :key="i">
				<image :src="o.shopGoods.url" style="width: 180rpx; height: 180rpx;"></image>
				<view class="flex-1 flex-between flex-column" style="padding-left: 30rpx; height: 180rpx;">
					<text style="line-height: 1; color: #D56065; font-weight: 600;">{{o.name}}</text>
					<text style="line-height: 1; color: #333; font-weight: 600;">{{o.price}}</text>
					<text style="line-height: 1; color: #333;">数X{{o.num}}</text>
				</view>
			</view>
			<view class="margin30" style="color: #333;">订单号：{{item.orderId}}</view>
			<view class="flex-end margin30" v-if="current==0">
				<view class="btn" @click="cancelFun(item.id)">取消</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				statusBarHeight: 0,
				barHeight: 0,
				menuHeight: 0,
				tabs: [{name: '待支付'}, {name: '待收货'}, {name: '已完成'}, {name: '已取消'}],
				current: 0,
				list: []
			}
		},
		async onLoad() {
			let that = this;
			wx.getSystemInfo({
				success(res) {
					let deviceWidth = wx.getSystemInfoSync().windowWidth
					that.statusBarHeight = Number(res.statusBarHeight) * ( 750 / deviceWidth ) 
					let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
					that.menuHeight = Number(menuButtonInfo.height) * ( 750 / deviceWidth )
					let barHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2
					that.barHeight = Number(barHeight) * ( 750 / deviceWidth )
				},
			});
			
		},
		async onShow() {
			await this.getList()
		},
		
		methods: {
			async cancelFun(id){
				const res = await this.$request(`/api/WeChat/shopOrderCancel?id=${id}`, {
					id: id
				})
				if(res.code===200) {
					this.$u.toast("操作成功")
					this.getList()
				}
			},
			
			async getList(){
				uni.showLoading()
				const res = await this.$request(`/api/WeChat/queryShopOrderList?state==${Number(this.current)+1}`, {
					state: this.current+1
				}, 'GET')
				uni.hideLoading()
				if(res.code===200) {
					console.log(res)
					this.list = res.data
				}
			},
			tabChange(e){
				this.current = e
				this.getList()
			}
		},
	}
</script>

<style lang="less" scoped>
	.topVue {
		width: 100%;
		background: #fff;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 99;
		.safeVue {
			width: 100%;
		}
	}
	.tabVue {
		width: 100%;
	}
	.item {
		width: 690rpx;
		background: #fff;
		border-radius: 20rpx;
		box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(178, 178, 178, 0.25), inset 0rpx 8rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
		.btn {
			width: 140rpx;
			height: 80rpx;
			border-radius: 20rpx;
			background: #D37430;
			color: #fff;
			line-height: 80rpx;
			text-align: center;
		}
	}
</style>